package com.aliyun.heiyu.powermaster.server.dao.impl;

import com.aliyun.heiyu.common.util.JdbcUtil;
import com.aliyun.heiyu.powermaster.server.dao.StateGridCapTaskItemDao;
import com.aliyun.heiyu.powermaster.server.dao.entity.StateGridCapTaskItemEntity;

import java.util.List;
import java.util.Map;

public class StateGridCapTaskItemImpl implements StateGridCapTaskItemDao {
    @Override
    public Map<String, String> findOneByCondition(String serverIp, String gmtCreate) {
        String sql = "SELECT * FROM state_grid_cap_task_item WHERE server_ip = ? AND status = 3 AND gmt_create <= ? " +
            "ORDER BY gmt_create DESC LIMIT 0,1";
        Object[] params = new Object[2];
        params[0] = serverIp;
        params[1] = gmtCreate;
        Map<String, String> map = JdbcUtil.queryForMap(sql, params);
        return map;
    }

    @Override
    public List<Map<String, String>> findByCondition(String serverIp, String startTime, String endTime) {
        //server_ip,startTime,endTime 为非空
        String sql = "SELECT * FROM state_grid_cap_task_item WHERE server_ip = ? and status = 3 AND gmt_create BETWEEN ? AND ?";
        Object[] params = new Object[3];
        params[0] = serverIp;
        params[1] = startTime;
        params[2] = endTime;
        List<Map<String, String>> list = JdbcUtil.queryForList_Map(sql, params);
        return list;
    }

    @Override
    public StateGridCapTaskItemEntity findLastOne(String ip) {
        String sql = "SELECT * FROM state_grid_cap_task_item WHERE server_ip = ? and status = ? ORDER BY gmt_create DESC limit 0,1";
        Object[] params = new Object[2];
        params[0] = ip;
        params[1] = 3;
        StateGridCapTaskItemEntity entity = JdbcUtil.queryForBean(sql,params,StateGridCapTaskItemEntity.class);
        return entity;
    }
}
